package com.skillworld.webapp.model.department;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.skillworld.webapp.model.util.dao.GenericDaoHibernate;

@Repository("DepartmentRankingDao")
public class DepartmentRankingDaoHibernate 
        extends GenericDaoHibernate<DepartmentRanking, Long> 
        implements DepartmentRankingDao {

    @SuppressWarnings("unchecked")
    public List<Department> topDepartments(int count)
    {
        return(List<Department>) getSession().createQuery(
                                "SELECT t.department FROM Tutorial t " +
                                "ORDER BY t.tutorialId DESC " +
                                "ORDER BY count(t.tutorialId) DESC")
                                .setFirstResult(0)
                                .setMaxResults(count)
                                .list();
    }
}
